﻿#include "precomp.h"
#include "jbaselineshapeitem.h"
#include "qwt_curve_fitter.h"

JBaseLineShapeItem::JBaseLineShapeItem(const QString &title) :
    QwtPlotShapeItem(title)
{
    setItemAttribute(QwtPlotItem::Legend, false);
    setLegendMode(QwtPlotShapeItem::LegendShape);
    setLegendIconSize(QSize(20, 20));
    setRenderHint(QwtPlotItem::RenderAntialiased, true);

    //
    QColor fillColor(0xfc, 0xcf, 0x83, 255);
    QPen pen(fillColor, 3);
    setPen(pen);
}

void JBaseLineShapeItem::setSamples(const QList<QVector<QPointF> > &groupsData)
{
    QPainterPath path;
#if 0
    QwtSplineCurveFitter splineFilter;
    splineFilter.setSplineSize(500);

    QListIterator<QVector<QPointF> > citerGroupsData(groupsData);
    while (citerGroupsData.hasNext()) {
        const QVector<QPointF> &groupData = citerGroupsData.next();
        path.addPolygon(splineFilter.fitCurve(QPolygonF(groupData)));
    }
#else
    QListIterator<QVector<QPointF> > citerGroupsData(groupsData);
    while (citerGroupsData.hasNext()) {
        path.addPolygon(citerGroupsData.next());
    }
#endif
    setShape(path);
}

